// ==UserScript==
// @name         [kesai]吾爱破解自动填写验证答案
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.52pojie.cn/*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var jq = jQuery.noConflict();
    var replys = ['谢谢楼主分享:Dweeqw', '感谢大佬的分享:Dweeqw', '大……大佬！', '谢谢分享~',  '正是想要的'];

    function rnd(n, m) {
        var random = Math.floor(Math.random() * (m - n + 1) + n);
        return random;
    }

    window.onload = function() {
        //自动填充页面下方的验证答案和回复用语
        var code_menu = jq('#seccodeqS0_menu');
        jq('input[name=secanswer]').attr("value", code_menu.text().split("答案：")[1])
        var reply = replys[rnd(0, replys.length - 1)]
        jq('#fastpostmessage').val(reply);
        jq('#fastpostmessage').css('background', 'none');
        checkState('#checksecqaaverify_qS0');
        jq('#append_parent').bind('DOMNodeInserted', changes);
    }

    //弹出回复自动填充验证答案和回复用语
    function changes() {
        if (jq('#seccodeqSA0_menu').length > 0) {
            var pop_code_menu = jq('#seccodeqSA0_menu');
            if (jq('#secqaaverify_qSA0').val().length > 0) return;
            jq('#secqaaverify_qSA0').attr('value', pop_code_menu.text().split("答案：")[1])
            checkState('#checksecqaaverify_qSA0');
        }
        if (jq('#postmessage').val().length > 0) return;
        var reply = replys[rnd(0, replys.length - 1)]
        jq('#postmessage').val(reply);
    }

    function checkState(id) {
        jq(id).children().attr('src', 'https://static.52pojie.cn/static/image/common/check_right.gif')
    }
})();